package juc.day01;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * @author wang hao
 * @date 2023-02-26 13:52
 */
public class Demo03 {
    public static void main(String[] args) throws InterruptedException, ExecutionException {

        ExecutorService threadPool = Executors.newFixedThreadPool(3);

        ArrayList<Callable<Integer>> callables = new ArrayList<>();
        callables.add(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                System.out.println("1");
                return 1;
            }
        });
        callables.add(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                try {
                    Thread.sleep(1000);
                    System.out.println("2");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                return 2;
            }
        });

        Integer integer = threadPool.invokeAny(callables);
        System.out.println(integer);


    }
}
